/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 16:06:20
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-04-23 17:30:13
 */
import { uploadType,regularRule, getAreaObj } from '@/utils/util'
import { getStore } from '@/utils/store'
import { cloneDeep } from 'lodash-es'
import { format } from 'path'
let userInfo = getStore('userInfo')
let materialsDic = [
	{
		label:"全部",
		value:"",
		type:"primary"
	},
	{
		label:"已归档",
		value:"1",
		type:"primary"
	},
	{
		label:"未归档",
		value:"0",
		type:"primary"
	}
]

// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '归属年份', prop: 'belongYear' },
		{ label: '老人姓名', prop: 'name' },
		{ label: '身份证号', prop: 'idCard',plusXing: '2,2' },
		{
			label: '手机号码',
			prop: 'telephone',
            plusXing: '2,2'
		},
		{
			label: '户籍地址',
			prop: 'cr_areas',
			type:"ApliyAreaSelect",
			propName: 'cr_areas_name',
		},
		{
			label: '申请时间',
			prop: 'applicationTime',
		},
		{
			label: '申请材料',
			prop: 'applicationFile',
		},
		{
			label: '评估材料',
			prop: 'estimateTable',
		},
		{
			label: '改造实施材料',
			prop: 'transformTable',
		},
		{
			label: '验收材料',
			prop: 'checkTable',
		}
	],
}

export const api = {
	index: 'view_file_bscAdaptOld_page'
}

export const baseConfig = {
	pageName: '适老化改造验收管理',
	// 数据字典
	dictcodes: ['ACCESS_LEVEL_COUNTRY'],
	rowKey: 'id',
	tipLabel: 'name',
	addLabel: '新增',
	api: {
		...api,
	},
	auth: {
		...api
	},
	paramsObj:{
		
	},
	// 当前行操作按钮
	menuBtn: [
		{
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		}
	],
	dialogConfig: {
		width: '80%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '老人姓名', prop: 'name', type: 'input', span: 8 },
			{ label: '身份证号', prop: 'idCard', type: 'input', span: 8 },
			{
				label: '手机号码',
				prop: 'telephone',
				span: 8,
			},
			{
				label: '户籍地区',
				type:"AplidAreaSelect",
				prop: 'cr_areas',
				span: 8,
			},
			{
				label: '申请时间',
				prop: 'applicationTimeBetween',
				type: 'daterange',
				format: 'YYYY年MM月DD',
				valueFormat: 'YYYY-MM-DD',
				span: 8,
			},
			{
				label: '申请材料',
				type:"select",
				prop: 'isWithApplyMaterial',
				dicData:materialsDic,
				span: 8,
			},
			{
				label: '评估材料',
				type:"select",
				prop: 'isWithAssessmentMaterial',
				dicData:materialsDic,
				span: 8,
			},
			{
				label: '改造实施材料',
				type:"select",
				prop: 'isWithImplementationMaterial',
				dicData:materialsDic,
				span: 8,
			},
			{
				label: '验收材料',
				type:"select",
				prop: 'isWithAcceptanceMaterial',
				dicData:materialsDic,
				span: 8,
			}
		],
	},
	// 列表
	tableConfig,
    saveFormate: async (form) => {
        let copyForm = cloneDeep(form)
		return new Promise((resolve, reject) => {
            let cr_areas_obj = getAreaObj(copyForm.cr_areas,'cr')
            let cr_areas_name_obj = getAreaObj(copyForm.cr_areas_name,'cr')
            let areas_obj = getAreaObj(copyForm.areas,'')
            let areas_name_obj = getAreaObj(copyForm.areas_name,'')

			resolve({
                ...copyForm,
                ...cr_areas_obj,
                ...areas_obj,
                ...cr_areas_name_obj,
                ...areas_name_obj,
                cr_areas:undefined,
                cr_areas_name:undefined,
                areas:undefined,
                areas_name:undefined
            })
		})
	},
	onLoadFormate: async (arr) => {
		let tableData = arr.map((item) => {
            // 处理区域
            item.cr_areas = getAreaObj(item,'cr')
            item.areas = getAreaObj(item,'')
			return item
		})
		return Promise.resolve(tableData)
	},
	beforeOnLoadFormate(form) {
		let copyForm = cloneDeep(form)
		// 处理搜索条件
		if(copyForm.applicationTimeBetween){
			copyForm.applicationTimeBetween[0]=copyForm.applicationTimeBetween[0]+' 00:00:00'
			copyForm.applicationTimeBetween[1]=copyForm.applicationTimeBetween[1]+' 23:59:59'
			copyForm.applicationTimeBetween = copyForm.applicationTimeBetween.join(',')
		}
		let cr_areas_obj = getAreaObj(copyForm.cr_areas,'cr')
        let cr_areas_name_obj = getAreaObj(copyForm.cr_areas_name,'cr')
        let areas_obj = getAreaObj(copyForm.areas,'')
        let areas_name_obj = getAreaObj(copyForm.areas_name,'')

		return new Promise((resolve, reject) => {
			resolve({
                ...copyForm,
                ...cr_areas_obj,
                ...areas_obj,
                ...cr_areas_name_obj,
                ...areas_name_obj,
                cr_areas:undefined,
                cr_areas_name:undefined,
                areas:undefined,
                areas_name:undefined
            })
		})
	},
}
